class Solution {
  /**
   * Use the reduce method in combination with the concat method to “flatten” an array of arrays into a single array that has all the elements of
   * the original arrays.
   * @param arr arr
   */
  flat(arr: Array<Array<any>>): Array<Array<any>> {
    return arr.reduce((cur, n) => cur.concat(n), []);
  }

  loop(val, test, update, body) {
    while (test(val)) {
      body(val);
      val = update(val);
    }
  }

  every1(arr, predict) {
    for (let e of arr) {
      if (!predict(e)) {
        return false;
      }
    }
    return true;
  }

  every2(arr, predict) {
    return arr.length > 0
      ? arr.reduce((cur, n) => cur && predict(n), true)
      : false;
  }

  /**
   * 计算最多的书写顺序
   * 1. 计算每种书写顺序有多少个字符集 reduce
   * 2. 找出数量最大的字符集对应的书写顺序 reduce
   */
}

const sol = new Solution();
const arrInArr = [[1, 2, 3], [1], [4, 5, 6]];
console.log(sol.flat(arrInArr));
console.log(arrInArr);
sol.loop(
  1,
  (i) => i < 10,
  (i) => i + 1,
  (i) => console.log(i)
);
console.log(sol.every1([2, 4, 6, 7], (e) => e % 2 == 0));
console.log(sol.every2([2, 4, 6, 7], (e) => e % 2 == 0));
